<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>cungrq.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CUNGRQ.1"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a>( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, K, LDA, LWORK, M, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      COMPLEX            A( LDA, * ), TAU( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CUNGRQ.17"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a> generates an M-by-N complex matrix Q with orthonormal rows,
</span><span class="comment">*</span><span class="comment">  which is defined as the last M rows of a product of K elementary
</span><span class="comment">*</span><span class="comment">  reflectors of order N
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Q  =  H(1)' H(2)' . . . H(k)'
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  as returned by <a name="CGERQF.23"></a><a href="cgerqf.f.html#CGERQF.1">CGERQF</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  M       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of rows of the matrix Q. M &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of columns of the matrix Q. N &gt;= M.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  K       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of elementary reflectors whose product defines the
</span><span class="comment">*</span><span class="comment">          matrix Q. M &gt;= K &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the (m-k+i)-th row must contain the vector which
</span><span class="comment">*</span><span class="comment">          defines the elementary reflector H(i), for i = 1,2,...,k, as
</span><span class="comment">*</span><span class="comment">          returned by <a name="CGERQF.41"></a><a href="cgerqf.f.html#CGERQF.1">CGERQF</a> in the last k rows of its array argument
</span><span class="comment">*</span><span class="comment">          A.
</span><span class="comment">*</span><span class="comment">          On exit, the M-by-N matrix Q.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The first dimension of the array A. LDA &gt;= max(1,M).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAU     (input) COMPLEX array, dimension (K)
</span><span class="comment">*</span><span class="comment">          TAU(i) must contain the scalar factor of the elementary
</span><span class="comment">*</span><span class="comment">          reflector H(i), as returned by <a name="CGERQF.50"></a><a href="cgerqf.f.html#CGERQF.1">CGERQF</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK))
</span><span class="comment">*</span><span class="comment">          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LWORK   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The dimension of the array WORK. LWORK &gt;= max(1,M).
</span><span class="comment">*</span><span class="comment">          For optimum performance LWORK &gt;= M*NB, where NB is the
</span><span class="comment">*</span><span class="comment">          optimal blocksize.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">          If LWORK = -1, then a workspace query is assumed; the routine
</span><span class="comment">*</span><span class="comment">          only calculates the optimal size of the WORK array, returns
</span><span class="comment">*</span><span class="comment">          this value as the first entry of the WORK array, and no error
</span><span class="comment">*</span><span class="comment">          message related to LWORK is issued by <a name="XERBLA.63"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument has an illegal value
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      COMPLEX            ZERO
      PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            LQUERY
      INTEGER            I, IB, II, IINFO, IWS, J, KK, L, LDWORK,
     $                   LWKOPT, NB, NBMIN, NX
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CLARFB.81"></a><a href="clarfb.f.html#CLARFB.1">CLARFB</a>, <a name="CLARFT.81"></a><a href="clarft.f.html#CLARFT.1">CLARFT</a>, <a name="CUNGR2.81"></a><a href="cungr2.f.html#CUNGR2.1">CUNGR2</a>, <a name="XERBLA.81"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX, MIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            <a name="ILAENV.87"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      EXTERNAL           <a name="ILAENV.88"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input arguments
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      LQUERY = ( LWORK.EQ.-1 )
      IF( M.LT.0 ) THEN
         INFO = -1
      ELSE IF( N.LT.M ) THEN
         INFO = -2
      ELSE IF( K.LT.0 .OR. K.GT.M ) THEN
         INFO = -3
      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
         INFO = -5
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.EQ.0 ) THEN
         IF( M.LE.0 ) THEN
            LWKOPT = 1
         ELSE
            NB = <a name="ILAENV.110"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="CUNGRQ.110"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a>'</span>, <span class="string">' '</span>, M, N, K, -1 )
            LWKOPT = M*NB
         END IF
         WORK( 1 ) = LWKOPT
<span class="comment">*</span><span class="comment">
</span>         IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
            INFO = -8
         END IF
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.121"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CUNGRQ.121"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a>'</span>, -INFO )
         RETURN
      ELSE IF( LQUERY ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( M.LE.0 ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span>      NBMIN = 2
      NX = 0
      IWS = M
      IF( NB.GT.1 .AND. NB.LT.K ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Determine when to cross over from blocked to unblocked code.
</span><span class="comment">*</span><span class="comment">
</span>         NX = MAX( 0, <a name="ILAENV.140"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 3, <span class="string">'<a name="CUNGRQ.140"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a>'</span>, <span class="string">' '</span>, M, N, K, -1 ) )
         IF( NX.LT.K ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Determine if workspace is large enough for blocked code.
</span><span class="comment">*</span><span class="comment">
</span>            LDWORK = M
            IWS = LDWORK*NB
            IF( LWORK.LT.IWS ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Not enough workspace to use optimal NB:  reduce NB and
</span><span class="comment">*</span><span class="comment">              determine the minimum value of NB.
</span><span class="comment">*</span><span class="comment">
</span>               NB = LWORK / LDWORK
               NBMIN = MAX( 2, <a name="ILAENV.153"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 2, <span class="string">'<a name="CUNGRQ.153"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a>'</span>, <span class="string">' '</span>, M, N, K, -1 ) )
            END IF
         END IF
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use blocked code after the first block.
</span><span class="comment">*</span><span class="comment">        The last kk rows are handled by the block method.
</span><span class="comment">*</span><span class="comment">
</span>         KK = MIN( K, ( ( K-NX+NB-1 ) / NB )*NB )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Set A(1:m-kk,n-kk+1:n) to zero.
</span><span class="comment">*</span><span class="comment">
</span>         DO 20 J = N - KK + 1, N
            DO 10 I = 1, M - KK
               A( I, J ) = ZERO
   10       CONTINUE
   20    CONTINUE
      ELSE
         KK = 0
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Use unblocked code for the first or only block.
</span><span class="comment">*</span><span class="comment">
</span>      CALL <a name="CUNGR2.178"></a><a href="cungr2.f.html#CUNGR2.1">CUNGR2</a>( M-KK, N-KK, K-KK, A, LDA, TAU, WORK, IINFO )
<span class="comment">*</span><span class="comment">
</span>      IF( KK.GT.0 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use blocked code
</span><span class="comment">*</span><span class="comment">
</span>         DO 50 I = K - KK + 1, K, NB
            IB = MIN( NB, K-I+1 )
            II = M - K + I
            IF( II.GT.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Form the triangular factor of the block reflector
</span><span class="comment">*</span><span class="comment">              H = H(i+ib-1) . . . H(i+1) H(i)
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLARFT.192"></a><a href="clarft.f.html#CLARFT.1">CLARFT</a>( <span class="string">'Backward'</span>, <span class="string">'Rowwise'</span>, N-K+I+IB-1, IB,
     $                      A( II, 1 ), LDA, TAU( I ), WORK, LDWORK )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Apply H' to A(1:m-k+i-1,1:n-k+i+ib-1) from the right
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLARFB.197"></a><a href="clarfb.f.html#CLARFB.1">CLARFB</a>( <span class="string">'Right'</span>, <span class="string">'Conjugate transpose'</span>, <span class="string">'Backward'</span>,
     $                      <span class="string">'Rowwise'</span>, II-1, N-K+I+IB-1, IB, A( II, 1 ),
     $                      LDA, WORK, LDWORK, A, LDA, WORK( IB+1 ),
     $                      LDWORK )
            END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Apply H' to columns 1:n-k+i+ib-1 of current block
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CUNGR2.205"></a><a href="cungr2.f.html#CUNGR2.1">CUNGR2</a>( IB, N-K+I+IB-1, IB, A( II, 1 ), LDA, TAU( I ),
     $                   WORK, IINFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Set columns n-k+i+ib:n of current block to zero
</span><span class="comment">*</span><span class="comment">
</span>            DO 40 L = N - K + I + IB, N
               DO 30 J = II, II + IB - 1
                  A( J, L ) = ZERO
   30          CONTINUE
   40       CONTINUE
   50    CONTINUE
      END IF
<span class="comment">*</span><span class="comment">
</span>      WORK( 1 ) = IWS
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CUNGRQ.221"></a><a href="cungrq.f.html#CUNGRQ.1">CUNGRQ</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
